package com.cdc.rxjava;

import android.util.Log;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by cdc on 2018/3/30.
 */

public class RxjavaThreadControlDemo {
    public void doThread() {
        Observable.just(100, 200, 300, 400)
                .subscribeOn(Schedulers.io()) // 指定 subscribe() 发生在 IO 线程
                .observeOn(AndroidSchedulers.mainThread()) // 指定 Subscriber 的回调发生在主线程
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer number) {
                        Log.d("RxjavaThreadControlDemo", "number:" + number);
                    }
                });
    }
}
